package com.mhg.collection.theSet;

import com.mhg.collection.bean.Student;

import java.util.Iterator;
import java.util.TreeSet;



public class Demo_03 {

	public static void main(String[] args) {
		//按照年龄为主要条件 姓名为次要条件进行排序
		TreeSet ts = new TreeSet();
		ts.add(new Student("lisi02",22));
		ts.add(new Student("lisi007",20));
		ts.add(new Student("lisi09",19));
		ts.add(new Student("lisi08",19));
		ts.add(new Student("lisi11",40));
		
		ts.add(new Student("lisi16",30));
		ts.add(new Student("lisi12",36));
		ts.add(new Student("lisi10",29));
		ts.add(new Student("lisi22",90));
		ts.add(new Student("lisi007",20));
		/*
		 * 在存储自定义数据类型时 add方法 依托于 重写的compareTo方法
		 * */
		Iterator it = ts.iterator();
		while(it.hasNext()){
			Student stu = (Student)it.next();
			System.out.println(stu.getName()+":"+stu.getAge());
		}

	}

}
